import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';

const RouterView = (props) => {
  const cartCom = props.routes.filter(v => v.component);
  const cartRed = props.routes.filter(v => v.redirect);
  return (
    <Switch>
      {
        cartCom.map((item, index) => {
          return <Route key={index} path={item.path} render={(props) => {
            return <item.component {...props} routes={item.children} />
          }} />
        })
      }
      {
        cartRed.map((item, index) => {
          return <Redirect key={index} to={item.redirect} />
        })
      }
    </Switch>
  )
}

export default RouterView;
